package Classic150;

import LinkedList.ListNode;

public class 删除排序链表中的重复元素2 {
    /*
        注意条件的设立，考虑各个情况
     */
    public ListNode deleteDuplicates(ListNode head) {
        if (head == null || head.next == null) return head;
        ListNode dummyHead = new ListNode(-1, head);
        ListNode pre = dummyHead;
        while (head != null) {
            if (head.next == null || head.val != head.next.val) {
                pre = pre.next;
                head = head.next;
            } else {
                int val = head.val;
                while (head != null && head.val == val) head = head.next;
                pre.next = head;
            }
        }
        return dummyHead.next;
    }
}
